package com.cskaoyan.day2.collection;

import java.util.ArrayList;
import java.util.Collection;

/**
 * @author Common-zhou
 * @since 2023-02-28 10:49
 */
public class CollectionDemo4 {
    public static void main(String[] args) {

        // 5 个学生
        Collection<Student> students = new ArrayList<>();
        Student student = new Student("张三", 19, "hubei");
        Student student1 = new Student("李四", 18, "beijing");
        students.add(student);
        students.add(student1);
        students.add(new Student("王五", 20, "henan"));
        students.add(new Student("赵六", 21, "hainan"));
        students.add(new Student("Java", 20, "wuhan"));

        System.out.println("-------------------删除之前-------------------");
        System.out.println(students);
        System.out.println(students.size());

        // 删除学生
        students.remove(student);
        System.out.println("-------------------删除之后-------------------");
        System.out.println(students);
        System.out.println(students.size());


        // 可以看一下里面有多少元素
        // size()

        // 想判断一下有没有张三同学
        // boolean  返回的是一个布尔值 ；代表是否包含这个元素
        boolean contains = students.contains(student);
        System.out.println(contains);

        // 想判断李四是不是存在。
        boolean contains1 = students.contains(student1);
        System.out.println(contains1);


    }
}

class Student {
    private String name;

    private int age;

    private String address;

    public Student(String name, int age, String address) {
        this.name = name;
        this.age = age;
        this.address = address;
    }

    public String getName() {
        return name;
    }

    public void setName(String name) {
        this.name = name;
    }

    public int getAge() {
        return age;
    }

    public void setAge(int age) {
        this.age = age;
    }

    public String getAddress() {
        return address;
    }

    public void setAddress(String address) {
        this.address = address;
    }

    @Override
    public String toString() {
        return "Student{" + "name='" + name + '\'' + ", age=" + age + ", address='" + address + '\'' + '}';
    }
}
